<?php 
header("Content-type: text/css");
require_once "../../../include/init.php";

//https://gist.github.com/bedeabza/10463089
function hexToHsl($hex) {
    $hex = array($hex[0].$hex[1], $hex[2].$hex[3], $hex[4].$hex[5]);
    $rgb = array_map(function($part) {
        return hexdec($part) / 255;
    }, $hex);

    $max = max($rgb);
    $min = min($rgb);

    $l = ($max + $min) / 2;

    if ($max == $min) {
        $h = $s = 0;
    } else {
        $diff = $max - $min;
        $s = $l > 0.5 ? $diff / (2 - $max - $min) : $diff / ($max + $min);

        switch($max) {
            case $rgb[0]:
                $h = ($rgb[1] - $rgb[2]) / $diff + ($rgb[1] < $rgb[2] ? 6 : 0);
                break;
            case $rgb[1]:
                $h = ($rgb[2] - $rgb[0]) / $diff + 2;
                break;
            case $rgb[2]:
                $h = ($rgb[0] - $rgb[1]) / $diff + 4;
                break;
        }

        $h /= 6;
    }

    return array(360*$h, 100*$s, 100*$l);
}
	//$link = "hsl("..", ".."%, ".."%)";

	$color = hexToHsl($theme['lc']);
	$link = "hsl(".$color[0].", ".$color[1]."%, ".$color[2]."%)";
	
	$color = hexToHsl($theme['tx']);
	$text = "hsl(".$color[0].", ".$color[1]."%, ".$color[2]."%)";

	$color = hexToHsl($theme['bc']);
	$border = "hsl(".$color[0].", ".$color[1]."%, ".$color[2]."%)";

	$color = hexToHsl($theme['bg']);
	$background = "hsl(".$color[0].", ".$color[1]."%, ".$color[2]."%)";
	$backgroundDark = "hsl(".$color[0].", ". $color[1] ."%, ".($color[2] > 10 ? $color[2] - 10 : 0 )."%)";
	$backgroundDarker = "hsl(".$color[0].", ". $color[1] ."%, ".($color[2] > 18 ? $color[2] - 18 : 0 )."%)";
	$backgroundLight = "hsl(".$color[0].", ". $color[1] ."%, ".($color[2] < 90 ? $color[2] + 10 : 100 )."%)";
	$backgroundLighter = "hsl(".$color[0].", ". $color[1] ."%, ".($color[2] < 70 ? $color[2] + 30 : 100 )."%)";	
	$backgroundL = $color[2];

	$color = hexToHsl($theme['fg']);
	$foreground = "hsl(".$color[0].", ".$color[1]."%, ".$color[2]."%)";
	$foregroundDark = "hsl(".$color[0].", ". $color[1] ."%, ".($color[2] > 10 ? $color[2] - 10 : 0 )."%)";
	$foregroundDarker = "hsl(".$color[0].", ". $color[1] ."%, ".($color[2] > 18 ? $color[2] - 18 : 0 )."%)";
	$foregroundLight = "hsl(".$color[0].", ". $color[1] ."%, ".($color[2] < 90 ? $color[2] + 10 : 100 )."%)";
	$foregroundLighter = "hsl(".$color[0].", ". $color[1] ."%, ".($color[2] < 82 ? $color[2] + 18 : 100 )."%)";	
	$foregroundL = $color[2];
?>
p,div,span {
	color:<?php echo $text; ?>;
}

a, .link {
	color: <?php echo $link; ?>; 
}

textarea,input[type="text"],select{
	background-color: <?php echo ($foregroundL < 50 ? $foregroundLight : $foregroundDark) ?>;
	color:<?php echo $text; ?>;
	border:0px;
}

body {
	background-color: <?php echo $background; ?>;
}

label {
	color: gray;
}

input[type="radio"]:checked+label {
	color: black;
}

input[type="checkbox"]:checked+label {
	color: red;
}

.topbar {
	background-color: <?php echo $backgroundDarker ?>;
}

.gotop {
	background-color: rgba(255, 255, 255, 0.5);
}

.gotop a {
	color: <?php echo $link; ?>;
}

.topicon {
	color: <?php echo $backgroundLighter; ?>;
}

.toggleblur {
	background-color: <?php echo $link; ?>;
	color: <?php echo $foreground; ?>;
}

.polloption{
	display:block;
	margin:5px;
	padding:5px;
	background-color: <?php echo $foregroundLighter; ?>;
	color: <?php echo $link; ?>;
}

.polloption:hover:not(.fixed),.voted{
	cursor: pointer;
	background-color: <?php echo $foregroundDarker; ?>;
	color: white;
}

.voteBar{
	background-color: <?php echo $link; ?>;
}

.tiselected {
	border-bottom: 2px solid <?php echo $foreground; ?>;
}

.alert {
	background-color: red;
}

#notifications {
	background-color:<?php echo $foreground; ?>;
	box-shadow: 1px 1px 1px black;
}

.notif{
	border-bottom:<?php echo $theme['bw']; ?>px solid #<?php echo $theme['bc']; ?>;
	background-color:<?php echo $foreground; ?>;
	color:<?php echo $text; ?> !important;
}

.notif .post_buttons{
	background-color:<?php echo $foreground; ?>;
}

.notif .text{
	color:<?php echo $text; ?> !important;
}

input[type="submit"] {
	background-color: <?php echo $link; ?>;
	color: <?php echo $foreground; ?>;
	border:0px;
}	

.new {
	background-color:<?php echo $foreground; ?>;
}

.side_element {
	background-color: #455f78;
	/*box-shadow: 1px 1px 1px black;*/
}

.side_element li:hover,.menu li:hover {
	background-color: <?php echo $backgroundDarker; ?> !important;
}

.side_element li:active {
	background-color: rgba(255, 255, 255, 0.25);
}

.uploadBox {
	box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px rgba(255, 255, 255, 0.1);
}

.delpic {
	color:red;
	background-color:white;
}

.formbtn {
	color:<?php echo $link; ?>; 
}

.formbtn label{
	color:<?php echo $link; ?>; 
}

.profile,.loader {
	background-color:<?php echo $topbar; ?>; 
	color:<?php echo $foreground; ?>; 
}

.listmenu li {
	background-color:black;
	color:white;
}

.listmenu li:hover {
	background-color:white;
	color:black;
}

.autl:hover li{
	background-color:lightgreen !important;
}

.rutl:hover li{
	background-color:crimson !important;
}

.unblock,.unmute,.block,.mute,.follow,
.unfollow,
.nsfw,
.unnsfw,
.profileMenu,
.listmenu {
	background-color: black;
	color: white;
	cursor: pointer;
}

.mute:hover,.block:hover,.follow:hover,
.nsfw:hover {
	background-color: lime;
}

.unmute:hover,.unblock:hover,.unfollow:hover,
.unnsfw:hover{
	background-color: crimson !important;
}

.unbookmark{
	color: crimson !important;
}

.unfav, .unreblog{
	color: red !important;
}

.element_pad > .post {
	border-left:2px solid <?php echo $link; ?>;
}
.post,
.rb,
.textonly,
.loadmore,
.postform,
.side_element,
.searchmobile
 {
	border: <?php echo $theme['bw']; ?>px solid #<?php echo $theme['bc']; ?>;
	border-radius: <?php echo $theme['br']; ?>px;
	background-color: <?php echo $foreground; ?>;
	/*box-shadow: 1px 1px 2px black;*/
}
	
.menu,.menu li {
	background-color: <?php echo ($foregroundL < 50 ? $foregroundLight : $foregroundDark) ?> !important;
}

.menu li:hover a {
	color: <?php echo $foreground; ?> !important;
}

.menu li a {
	color: <?php echo $link; ?> !important;  
}

.menu {
	box-shadow: 1px 1px 2px black;
}

.previewpost,.userinfo {
	background-color: <?php echo ($foregroundL < 50 ? $foregroundLight : $foregroundDark) ?>;
	border: 1px solid <?php echo ($foregroundL < 50 ? $foregroundLight : $foregroundDark) ?>;
	box-shadow: 1px 1px 1px rgba(0,0,0,1);
}

.icon {
	background-color: black;
}

.post_footer {
	background-color: <?php echo ($foregroundL < 50 ? $foregroundLighter : $foregroundDarker) ?>;
	border-radius: 0px 0px <?php echo $theme['br']; ?>px <?php echo $theme['br']; ?>px;
}

.felem a:hover > span {
	color: <?php echo $backgroundLighter; ?>;
	background-color: <?php echo $backgroundDarker ?> !important;
	border: <?php echo $theme['bw']; ?>px solid #<?php echo $theme['bc']; ?>;
	border-radius:3px;
}	

.public::after {
	content: '';
}

.unlisted::after {
	content: '';
}

.private::after {
	content: '';
}

.direct::after {
	content: '';
}

.sensitive::after {
	content: '';
}

.post_buttons {
	color: #404040;
}

.reply {
	background-color: <?php echo ($foregroundL < 50 ? $foregroundLighter : $foregroundDarker) ?>;
	border-bottom: 2px solid <?php echo $foreground; ?>;
}

.note {
	background-color: #ccc;
}

.button {
	background-color: white;
}

.setting label {
	background-color: lightgray;
	box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px rgba(255, 255, 255, 0.1);
}

.setting input[type="radio"]:checked+label {
	background-color: <?php echo $link; ?>; ;
	box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
	color:  <?php echo $foreground; ?>; ;
}
